(* Content-type: application/mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 6.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       145,          7]
NotebookDataLength[     65559,       1275]
NotebookOptionsPosition[     64642,       1246]
NotebookOutlinePosition[     64977,       1261]
CellTagsIndexPosition[     64934,       1258]
WindowFrame->Generic
ContainsDynamic->False*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"NewAgent", "[", 
    RowBox[{
    "agentIndex_Integer", ",", " ", "money_Real", ",", " ", 
     "employerIndex_Integer", ",", " ", "wage_Real", ",", "wageDemand_Real", 
     ",", "employeeIndices_List"}], "]"}], " ", ":=", "\n", "   ", 
   RowBox[{"{", 
    RowBox[{
    "agentIndex", ",", " ", "money", ",", " ", "employerIndex", ",", " ", 
     "wage", ",", "wageDemand", ",", "employeeIndices"}], "}"}]}], 
  "\n"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"NewAgent", "[", 
    RowBox[{"agentIndex_Integer", ",", " ", "money_Real"}], "]"}], " ", ":=", 
   " ", "\n", "\t", 
   RowBox[{"NewAgent", "[", 
    RowBox[{
    "agentIndex", ",", " ", "money", ",", " ", "0", ",", " ", "0.0", ",", 
     "0.0", ",", 
     RowBox[{"{", "}"}]}], "]"}]}], "\n"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"{", 
     RowBox[{
     "agentAgentIndex", ",", " ", "agentMoney", ",", " ", 
      "agentEmployerIndex", ",", " ", "agentWage", ",", "agentWageDemand", 
      ",", "  ", "agentEmployeeIndices"}], "}"}], " ", "=", " ", 
    RowBox[{"Range", "[", "6", "]"}]}], ";"}], "\n"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"IsEmployer", "[", "agent_List", "]"}], " ", ":=", "\n", "   ", 
   RowBox[{
    RowBox[{"Length", "[", 
     RowBox[{
     "agent", "\[LeftDoubleBracket]", "agentEmployeeIndices", 
      "\[RightDoubleBracket]"}], "]"}], " ", ">", " ", "0"}]}], 
  "\n"}], "\n", 
 RowBox[{
  RowBox[{"IsEmployee", "[", "agent_List", "]"}], " ", ":=", "\n", "   ", 
  RowBox[{
   RowBox[{
   "agent", "\[LeftDoubleBracket]", "agentEmployerIndex", 
    "\[RightDoubleBracket]"}], "!=", "0"}]}]}], "Input",
 CellChangeTimes->{{3.411157302588436*^9, 3.411157308538416*^9}, {
  3.411160030863524*^9, 3.411160037438905*^9}, {3.411801216201227*^9, 
  3.411801230291285*^9}, {3.41180273722863*^9, 3.4118027373982153`*^9}, {
  3.4126302960381603`*^9, 3.412630321092561*^9}, {3.412631951234281*^9, 
  3.41263196071206*^9}, {3.41269826127391*^9, 3.412698261359168*^9}, {
  3.4152145192173777`*^9, 3.415214572536306*^9}, {3.415798938042679*^9, 
  3.4157989563525677`*^9}, {3.41579906496579*^9, 3.415799085407782*^9}, {
  3.415799144250696*^9, 3.415799149352521*^9}, {3.41579939096274*^9, 
  3.415799393154327*^9}, {3.415799454189752*^9, 3.415799454803924*^9}, {
  3.415800063431778*^9, 3.415800085083846*^9}, {3.417363041737132*^9, 
  3.4173630433790607`*^9}, {3.419779581409499*^9, 3.419779645736079*^9}, {
  3.420137093401273*^9, 3.42013715336703*^9}, {3.4201382753580713`*^9, 
  3.420138289201029*^9}, {3.438127633205831*^9, 3.438127651331582*^9}, {
  3.438127684406559*^9, 3.438127697881446*^9}, {3.438225722379819*^9, 
  3.438225724537928*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"NewEconomy", "[", 
   RowBox[{"numAgents_Integer", ",", " ", "initialMoneyEndowment_Real"}], 
   "]"}], " ", ":=", 
  RowBox[{"NewEconomy", "[", 
   RowBox[{
   "numAgents", ",", "initialMoneyEndowment", ",", "initialMoneyEndowment"}], 
   "]"}]}]], "Input",
 CellChangeTimes->{{3.4219406367210484`*^9, 3.421940649321083*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"NewEconomy", "[", 
    RowBox[{
    "numAgents_Integer", ",", " ", "initialMoneyEndowment_Real", ",", 
     "initialExpectation_Real"}], "]"}], " ", ":=", "\n", "   ", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"economy", "=", 
       RowBox[{"{", "}"}]}], "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"Do", "[", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{"economy", "=", 
          RowBox[{"Append", "[", 
           RowBox[{"economy", ",", 
            RowBox[{"NewAgent", "[", 
             RowBox[{
             "i", ",", "initialMoneyEndowment", ",", "0", ",", 
              "initialExpectation", ",", "initialExpectation", ",", 
              RowBox[{"{", "}"}]}], "]"}]}], "]"}]}], ";"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"{", 
         RowBox[{"i", ",", "numAgents"}], "}"}]}], "\[IndentingNewLine]", 
       "]"}], ";", "\[IndentingNewLine]", 
      RowBox[{"economy", "=", 
       RowBox[{"Append", "[", 
        RowBox[{
         RowBox[{"{", "economy", "}"}], ",", "0.0"}], "]"}]}], ";", 
      "\[IndentingNewLine]", "economy"}]}], "\[IndentingNewLine]", "]"}]}], 
  "\n"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{"economyAgents", ",", " ", "economyEffectiveDemand"}], "}"}], " ",
    "=", " ", 
   RowBox[{"Range", "[", "2", "]"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.415799528103033*^9, 3.415799531493127*^9}, {
  3.415893440624948*^9, 3.415893444054879*^9}, {3.41736301237821*^9, 
  3.417363013011167*^9}, {3.419711662123015*^9, 3.4197116622905483`*^9}, {
  3.419712788097172*^9, 3.419712791154002*^9}, {3.419771471075878*^9, 
  3.419771484738254*^9}, {3.419779676132296*^9, 3.419779677013598*^9}, {
  3.419781281272551*^9, 3.4197812831997147`*^9}, {3.4197866076375923`*^9, 
  3.419786608384337*^9}, {3.419786819230647*^9, 3.4197868193856907`*^9}, {
  3.4197873208972597`*^9, 3.419787325507401*^9}, {3.419788659929057*^9, 
  3.419788664822219*^9}, {3.420059224619059*^9, 3.420059230963423*^9}, {
  3.420059607133984*^9, 3.42005965681487*^9}, {3.420059871830875*^9, 
  3.4200598784328527`*^9}, {3.420060048383453*^9, 3.42006005316908*^9}, {
  3.4200603563911753`*^9, 3.420060359153995*^9}, {3.420060483757576*^9, 
  3.4200604861219597`*^9}, {3.420060593058393*^9, 3.4200606197881002`*^9}, {
  3.420113781033086*^9, 3.420113786695277*^9}, {3.4201142722217503`*^9, 
  3.420114276534668*^9}, {3.4201154231333437`*^9, 3.420115433085629*^9}, {
  3.420134612887766*^9, 3.4201346659901943`*^9}, {3.4201347818473473`*^9, 
  3.4201347823148537`*^9}, {3.4201348133175077`*^9, 3.42013495363831*^9}, {
  3.420134988777029*^9, 3.420135003029448*^9}, {3.420135078713896*^9, 
  3.420135139975548*^9}, {3.4201351712024307`*^9, 3.420135209798954*^9}, {
  3.420135617738987*^9, 3.4201356628050537`*^9}, {3.420135707475505*^9, 
  3.420135708854506*^9}, {3.420137029298874*^9, 3.420137030243205*^9}, {
  3.420137139095875*^9, 3.420137139158382*^9}, {3.4201387527625237`*^9, 
  3.420138782184455*^9}, {3.421940654550926*^9, 3.421940676891038*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"CouldEmployMe", " ", "=", " ", 
    RowBox[{"Function", "[", 
     RowBox[{"x", ",", " ", 
      RowBox[{"!", " ", 
       RowBox[{"IsEmployee", "[", "x", "]"}]}]}], "]"}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"SelectEmployer", "[", 
   RowBox[{"economy_List", ",", " ", "agentIndex_Integer"}], "]"}], ":=", 
  "\[IndentingNewLine]", 
  RowBox[{"Module", "[", " ", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
     "potentialEmployerIndices", ",", " ", "weights", ",", " ", "NotMe", ",", 
      "x"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"NotMe", " ", "=", " ", 
      RowBox[{"Function", "[", 
       RowBox[{"x", ",", " ", 
        RowBox[{
         RowBox[{
         "x", "\[LeftDoubleBracket]", "agentAgentIndex", 
          "\[RightDoubleBracket]"}], " ", "!=", " ", "agentIndex"}]}], 
       "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"potentialEmployerIndices", "=", "\[IndentingNewLine]", 
      RowBox[{"Map", "[", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{
         "#", "\[LeftDoubleBracket]", "agentAgentIndex", 
          "\[RightDoubleBracket]"}], " ", "&"}], ",", " ", 
        "\[IndentingNewLine]", 
        RowBox[{"Select", "[", 
         RowBox[{
          RowBox[{
          "economy", "\[LeftDoubleBracket]", "economyAgents", 
           "\[RightDoubleBracket]"}], ",", " ", 
          RowBox[{
           RowBox[{
            RowBox[{"CouldEmployMe", "[", "#", "]"}], "&&", 
            RowBox[{"NotMe", "[", "#", "]"}], " ", "&&", 
            RowBox[{
             RowBox[{
             "#", "\[LeftDoubleBracket]", "agentMoney", 
              "\[RightDoubleBracket]"}], ">", "0.0"}]}], "&"}]}], "]"}]}], 
       "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"weights", "=", 
      RowBox[{"Map", "[", 
       RowBox[{
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{
           "economy", "\[LeftDoubleBracket]", "economyAgents", 
            "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "#", 
           "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "agentMoney", 
          "\[RightDoubleBracket]"}], "&"}], ",", "potentialEmployerIndices"}],
        "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{
        RowBox[{"Length", "[", "weights", "]"}], ">", "0"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"RandomChoice", "[", 
        RowBox[{"weights", "\[Rule]", "potentialEmployerIndices"}], "]"}], 
       ",", "\[IndentingNewLine]", "0"}], "\[IndentingNewLine]", "]"}]}]}], 
   "\[IndentingNewLine]", "]"}]}]}], "Input",
 CellChangeTimes->{{3.410935230843298*^9, 3.410935236117745*^9}, {
   3.410935771909264*^9, 3.410935774745442*^9}, {3.4109358127368526`*^9, 
   3.410935818787415*^9}, {3.411111817170206*^9, 3.411111917422976*^9}, {
   3.411111957012649*^9, 3.4111119641774187`*^9}, {3.411112189213213*^9, 
   3.411112197427693*^9}, 3.41114389057719*^9, {3.411147330322069*^9, 
   3.4111473359418383`*^9}, {3.411147399541662*^9, 3.411147405498465*^9}, {
   3.411148423539577*^9, 3.411148429890028*^9}, {3.4111501561654997`*^9, 
   3.411150163180007*^9}, {3.411152460411973*^9, 3.411152466057232*^9}, {
   3.4111571497805023`*^9, 3.4111571596554737`*^9}, {3.411157322655035*^9, 
   3.411157378297347*^9}, {3.411160096510111*^9, 3.4111601379663153`*^9}, {
   3.412615937283072*^9, 3.412615953270856*^9}, {3.412615985944646*^9, 
   3.412616035253768*^9}, {3.412616099918748*^9, 3.4126161057988243`*^9}, {
   3.412616546076017*^9, 3.412616561744522*^9}, {3.412616948604382*^9, 
   3.4126169519326763`*^9}, {3.412617479458653*^9, 3.4126175028276997`*^9}, {
   3.412617606683792*^9, 3.412617610764843*^9}, {3.4126176413181334`*^9, 
   3.412617648668116*^9}, {3.412617985767558*^9, 3.412617996225664*^9}, {
   3.412618457579791*^9, 3.412618472611073*^9}, {3.4126185912031612`*^9, 
   3.412618653701069*^9}, {3.4126187464440947`*^9, 3.412618775991205*^9}, {
   3.412621047705937*^9, 3.412621087089539*^9}, {3.412621345134342*^9, 
   3.412621345691998*^9}, {3.412628624111128*^9, 3.412628624756195*^9}, {
   3.4126291124451*^9, 3.412629127548348*^9}, {3.4126296579235897`*^9, 
   3.4126296673318987`*^9}, {3.4126300422424507`*^9, 3.412630042782455*^9}, {
   3.412630330154985*^9, 3.412630331699573*^9}, {3.412698209443605*^9, 
   3.412698231471389*^9}, {3.412699116473144*^9, 3.412699132293827*^9}, {
   3.412878598810296*^9, 3.4128786354968863`*^9}, {3.4128803301657133`*^9, 
   3.412880330855919*^9}, {3.412880368361305*^9, 3.412880415613673*^9}, {
   3.412880851945798*^9, 3.412880855459969*^9}, {3.4128809007074633`*^9, 
   3.412880928599516*^9}, {3.412881145119446*^9, 3.412881181810401*^9}, {
   3.412882184017763*^9, 3.412882191926948*^9}, {3.412893163800309*^9, 
   3.412893244637185*^9}, {3.412893855654799*^9, 3.4128938925620213`*^9}, {
   3.412893923726882*^9, 3.412893944200363*^9}, {3.412894639007164*^9, 
   3.4128947578778343`*^9}, {3.412895143545073*^9, 3.4128951691038857`*^9}, {
   3.412896286368445*^9, 3.412896294577921*^9}, {3.4128964784473057`*^9, 
   3.412896513339312*^9}, {3.41290364324196*^9, 3.412903662256116*^9}, {
   3.412903890498188*^9, 3.412903899468894*^9}, {3.412904283115891*^9, 
   3.412904291738737*^9}, {3.4129045291158524`*^9, 3.412904540546077*^9}, {
   3.412905284677387*^9, 3.4129053306930857`*^9}, {3.412908343334042*^9, 
   3.4129083458407393`*^9}, {3.412908532196623*^9, 3.412908534861174*^9}, {
   3.415223197787277*^9, 3.415223236870234*^9}, {3.415224039710512*^9, 
   3.415224040936511*^9}, {3.4152246371631517`*^9, 3.415224643356964*^9}, {
   3.415277776920154*^9, 3.415277851997375*^9}, {3.4152779489829903`*^9, 
   3.415277953710676*^9}, {3.41579874357615*^9, 3.4157987506596003`*^9}, {
   3.415798971028804*^9, 3.415798976259625*^9}, {3.415884624042028*^9, 
   3.4158846340598173`*^9}, {3.4158855388517303`*^9, 3.415885600355538*^9}, {
   3.41588573767542*^9, 3.4158857399355497`*^9}, {3.415885893301136*^9, 
   3.4158858998854427`*^9}, {3.415890431964816*^9, 3.415890448102004*^9}, {
   3.415890719113674*^9, 3.41589072008659*^9}, {3.416067268028819*^9, 
   3.4160673121035357`*^9}, {3.416067502173562*^9, 3.416067502294972*^9}, {
   3.416067542024433*^9, 3.416067565314657*^9}, {3.4160675958028812`*^9, 
   3.416067681955121*^9}, {3.416068186996765*^9, 3.416068218038301*^9}, {
   3.41606825424662*^9, 3.416068260727365*^9}, 3.4164884446894712`*^9, {
   3.416489090904464*^9, 3.4164891313502083`*^9}, {3.416489278803137*^9, 
   3.416489296617712*^9}, {3.416489331791388*^9, 3.4164893995983458`*^9}, {
   3.416490436029159*^9, 3.416490438160392*^9}, {3.416493930295109*^9, 
   3.416493938722186*^9}, {3.416496256790168*^9, 3.416496261830337*^9}, {
   3.41649649746987*^9, 3.4164964976056643`*^9}, {3.416496731787385*^9, 
   3.416496731962901*^9}, {3.4164985860344667`*^9, 3.416498592108512*^9}, {
   3.416498683152585*^9, 3.4164986981055307`*^9}, {3.416498749086822*^9, 
   3.416498771972809*^9}, {3.416499177796069*^9, 3.41649918020994*^9}, {
   3.416501383974391*^9, 3.416501395677238*^9}, {3.416503598825938*^9, 
   3.416503606637207*^9}, {3.416503804033966*^9, 3.416503813052302*^9}, {
   3.416506328607017*^9, 3.416506328840934*^9}, {3.416506538043227*^9, 
   3.4165065576896276`*^9}, {3.416508964858837*^9, 3.416508965154388*^9}, {
   3.416511854076303*^9, 3.4165118643936357`*^9}, {3.416584728394733*^9, 
   3.416584759657981*^9}, {3.416585648921274*^9, 3.416585656821596*^9}, {
   3.4165858101140137`*^9, 3.4165858541904583`*^9}, {3.416586040991674*^9, 
   3.416586051926882*^9}, {3.417362214060495*^9, 3.41736230005196*^9}, {
   3.417362849779399*^9, 3.417362867880507*^9}, {3.417363048000194*^9, 
   3.4173630526585608`*^9}, {3.41736330273248*^9, 3.417363309383918*^9}, {
   3.41736337107139*^9, 3.4173633731133537`*^9}, {3.4173640957592688`*^9, 
   3.417364122223961*^9}, {3.417364169082543*^9, 3.41736417199666*^9}, {
   3.4174504364632072`*^9, 3.417450478792384*^9}, {3.41753418221277*^9, 
   3.417534186296301*^9}, {3.417534242962344*^9, 3.41753426460984*^9}, {
   3.4178803265267*^9, 3.417880414274228*^9}, {3.417880498193008*^9, 
   3.417880560486306*^9}, {3.417882822022492*^9, 3.4178828533716*^9}, {
   3.417882899307931*^9, 3.417882899585539*^9}, {3.417883378992395*^9, 
   3.41788338189299*^9}, {3.4185734906354923`*^9, 3.418573499555492*^9}, {
   3.418662531565984*^9, 3.418662535920465*^9}, {3.4193504471088047`*^9, 
   3.419350484684773*^9}, {3.419351057409515*^9, 3.419351059097084*^9}, {
   3.419686683471016*^9, 3.419686699916424*^9}, {3.419690634330778*^9, 
   3.419690638764969*^9}, {3.419692665629871*^9, 3.419692669600191*^9}, {
   3.419692701096126*^9, 3.4196927546176147`*^9}, {3.420137093514201*^9, 
   3.42013711242068*^9}, {3.420138275457654*^9, 3.420138289226342*^9}, {
   3.421864433091714*^9, 3.4218644507529993`*^9}, {3.4220311579360247`*^9, 
   3.422031187146494*^9}, 3.438127828917547*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"JoinFirm", "[", 
   RowBox[{
   "economy_List", ",", " ", "agentIndex_Integer", ",", " ", 
    "employerIndex_Integer"}], "]"}], " ", ":=", "\n", "   ", 
  RowBox[{"Module", "[", " ", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", " ", "=", " ", "economy"}], ",", " ", 
      "employees"}], "}"}], ",", "\n", "      ", 
    RowBox[{
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{
       "economyAgents", ",", " ", "agentIndex", ",", " ", 
        "agentEmployerIndex"}], "\[RightDoubleBracket]"}], " ", "=", " ", 
      "employerIndex"}], ";", "\n", "      ", 
     RowBox[{"employees", " ", "=", " ", 
      RowBox[{
       RowBox[{
        RowBox[{
        "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
         "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "employerIndex", 
        "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
       "agentEmployeeIndices", "\[RightDoubleBracket]"}]}], ";", "\n", 
     "      ", 
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{
       "economyAgents", ",", " ", "employerIndex", ",", " ", 
        "agentEmployeeIndices"}], "\[RightDoubleBracket]"}], " ", "=", " ", 
      RowBox[{"Append", "[", 
       RowBox[{"employees", ",", " ", "agentIndex"}], "]"}]}], ";", "\n", 
     "      ", "nextEconomy"}]}], "\n", "   ", "]"}]}]], "Input",
 CellChangeTimes->{{3.4111108836792803`*^9, 3.4111108934593973`*^9}, {
   3.4111573856283817`*^9, 3.41115741567395*^9}, 3.421864465687252*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"LeaveFirm", "[", 
   RowBox[{
   "economy_List", ",", " ", "agentIndex_Integer", ",", " ", 
    "employerIndex_Integer"}], "]"}], " ", ":=", "\n", "   ", 
  RowBox[{"Module", "[", " ", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", " ", "=", " ", "economy"}], ",", " ", 
      "employees"}], "}"}], ",", "\n", "     ", 
    RowBox[{
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{
       "economyAgents", ",", " ", "agentIndex", ",", " ", 
        "agentEmployerIndex"}], "\[RightDoubleBracket]"}], " ", "=", " ", 
      "0"}], ";", "\[IndentingNewLine]", 
     RowBox[{"employees", " ", "=", " ", 
      RowBox[{
       RowBox[{
        RowBox[{
        "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
         "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "employerIndex", 
        "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
       "agentEmployeeIndices", "\[RightDoubleBracket]"}]}], ";", "\n", 
     "     ", 
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{
       "economyAgents", ",", " ", "employerIndex", ",", " ", 
        "agentEmployeeIndices"}], "\[RightDoubleBracket]"}], " ", "=", " ", 
      RowBox[{"DeleteCases", "[", 
       RowBox[{"employees", ",", " ", "agentIndex"}], "]"}]}], ";", "\n", 
     "     ", "nextEconomy"}]}], "\n", "   ", "]"}]}]], "Input",
 CellChangeTimes->{{3.4111108629099483`*^9, 3.4111108759084473`*^9}, {
   3.411157436502081*^9, 3.4111574882262793`*^9}, {3.417450526612818*^9, 
   3.417450557363447*^9}, {3.4185752261125727`*^9, 3.418575230582069*^9}, {
   3.4196116878642178`*^9, 3.4196117132735643`*^9}, {3.4196867104823914`*^9, 
   3.419686717952626*^9}, {3.419701148266892*^9, 3.419701153195076*^9}, {
   3.419708835982917*^9, 3.419708843189983*^9}, {3.419774387544799*^9, 
   3.419774390264353*^9}, {3.4197752087096567`*^9, 3.41977520907365*^9}, {
   3.4197768428066683`*^9, 3.419776872665956*^9}, {3.419777140099923*^9, 
   3.4197771428805523`*^9}, {3.419779702608721*^9, 3.419779706682494*^9}, {
   3.419780035144308*^9, 3.4197800528175898`*^9}, 3.419786734791095*^9, 
   3.4218644751731653`*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"HiringRule", "[", 
   RowBox[{"economy_List", ",", " ", "agentIndex_Integer"}], "]"}], ":=", 
  "\n", "   ", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", " ", "=", " ", "economy"}], ",", " ", 
      RowBox[{"agent", " ", "=", " ", 
       RowBox[{
        RowBox[{
        "economy", "\[LeftDoubleBracket]", "economyAgents", 
         "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "agentIndex", 
        "\[RightDoubleBracket]"}]}], ",", "potentialEmployerIndex", ",", 
      "wageOffer", ",", "wageDemand"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"!", 
        RowBox[{"IsEmployer", "[", "agent", "]"}]}], ",", " ", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"potentialEmployerIndex", "=", 
         RowBox[{"SelectEmployer", "[", 
          RowBox[{"nextEconomy", ",", " ", "agentIndex"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"If", "[", 
         RowBox[{
          RowBox[{"potentialEmployerIndex", " ", "!=", " ", "0"}], ",", 
          "\[IndentingNewLine]", 
          RowBox[{
           RowBox[{"wageDemand", "=", 
            RowBox[{
             RowBox[{
              RowBox[{
              "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
               "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
              "agentIndex", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]",
              "agentWageDemand", "\[RightDoubleBracket]"}]}], ";", 
           "\[IndentingNewLine]", 
           RowBox[{"wageOffer", "=", 
            RowBox[{"Min", "[", 
             RowBox[{
              RowBox[{"RandomReal", "[", 
               RowBox[{"{", 
                RowBox[{"wageDemand", ",", 
                 RowBox[{"wageDemand", "*", "2.0"}]}], "}"}], "]"}], ",", 
              RowBox[{
               RowBox[{
                RowBox[{
                "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
                 "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
                "potentialEmployerIndex", "\[RightDoubleBracket]"}], 
               "\[LeftDoubleBracket]", "agentMoney", 
               "\[RightDoubleBracket]"}]}], "]"}]}], ";", 
           "\[IndentingNewLine]", 
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{"wageOffer", ">", "wageDemand"}], ",", 
             "\[IndentingNewLine]", 
             RowBox[{
              RowBox[{"If", "[", 
               RowBox[{
                RowBox[{"IsEmployee", "[", "agent", "]"}], ",", 
                "\[IndentingNewLine]", 
                RowBox[{
                 RowBox[{"nextEconomy", "=", 
                  RowBox[{"LeaveFirm", "[", 
                   RowBox[{"nextEconomy", ",", "agentIndex", ",", 
                    RowBox[{
                    "agent", "\[LeftDoubleBracket]", "agentEmployerIndex", 
                    "\[RightDoubleBracket]"}]}], "]"}]}], ";"}]}], 
               "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
              RowBox[{"nextEconomy", " ", "=", " ", 
               RowBox[{"JoinFirm", "[", 
                RowBox[{
                "nextEconomy", ",", " ", "agentIndex", ",", " ", 
                 "potentialEmployerIndex"}], "]"}]}], ";", 
              "\[IndentingNewLine]", 
              RowBox[{
               RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
                RowBox[{
                "economyAgents", ",", "agentIndex", ",", "agentWageDemand"}], 
                "\[RightDoubleBracket]"}], "=", "wageOffer"}], ";"}]}], 
            "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
           RowBox[{"agent", " ", "=", " ", 
            RowBox[{
             RowBox[{
             "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
              "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "agentIndex",
              "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", 
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{"!", 
              RowBox[{"IsEmployee", "[", "agent", "]"}]}], ",", 
             "\[IndentingNewLine]", 
             RowBox[{
              RowBox[{
               RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
                RowBox[{
                "economyAgents", ",", "agentIndex", ",", "agentWageDemand"}], 
                "\[RightDoubleBracket]"}], "=", 
               RowBox[{
                RowBox[{"RandomReal", "[", "]"}], "*", 
                RowBox[{
                 RowBox[{
                  RowBox[{
                  "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
                   "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
                  "agentIndex", "\[RightDoubleBracket]"}], 
                 "\[LeftDoubleBracket]", "agentWageDemand", 
                 "\[RightDoubleBracket]"}]}]}], ";"}]}], 
            "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", 
         "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", 
     "\[IndentingNewLine]", "nextEconomy"}]}], "\[IndentingNewLine]", 
   "]"}]}]], "Input",
 CellChangeTimes->{{3.410935308642704*^9, 3.410935384070157*^9}, {
   3.4109355676328173`*^9, 3.410935633554556*^9}, {3.4109356744555187`*^9, 
   3.41093568619631*^9}, {3.411110713207348*^9, 3.411110837289171*^9}, {
   3.411110912649807*^9, 3.4111109135963793`*^9}, {3.4111114713087*^9, 
   3.4111114797799997`*^9}, {3.411143681865135*^9, 3.411143806969679*^9}, {
   3.411147364918665*^9, 3.4111473854508953`*^9}, {3.4111484488976793`*^9, 
   3.4111487036070633`*^9}, {3.411149826521165*^9, 3.411149848140197*^9}, {
   3.4111501145043097`*^9, 3.411150137710322*^9}, {3.41115247172666*^9, 
   3.41115247740208*^9}, {3.41115344401653*^9, 3.411153450009906*^9}, {
   3.411153511909754*^9, 3.41115373361162*^9}, {3.411156865640407*^9, 
   3.4111568722487583`*^9}, {3.411157091265347*^9, 3.4111570955610447`*^9}, {
   3.411157494055934*^9, 3.411157501705926*^9}, {3.412698384252178*^9, 
   3.412698427283291*^9}, {3.4126985127851458`*^9, 3.412698576016924*^9}, {
   3.412698610548118*^9, 3.412698733324183*^9}, {3.412698773259623*^9, 
   3.412698782116252*^9}, {3.412698932349044*^9, 3.4126989385928926`*^9}, 
   3.4126994486438513`*^9, 3.4126995154646997`*^9, {3.412699558731985*^9, 
   3.412699564175725*^9}, {3.412878848253405*^9, 3.412878904296283*^9}, {
   3.4128795962969112`*^9, 3.412879774595882*^9}, {3.412880433640954*^9, 
   3.412880445421577*^9}, {3.412881206601487*^9, 3.412881245223741*^9}, {
   3.4128815424933987`*^9, 3.412881579393071*^9}, {3.412881827894569*^9, 
   3.41288185646243*^9}, {3.412882152758533*^9, 3.412882171592383*^9}, {
   3.412893138436863*^9, 3.412893152834339*^9}, {3.412905682361087*^9, 
   3.412905682954855*^9}, 3.415909520315063*^9, {3.416065942144746*^9, 
   3.416065987175173*^9}, {3.4160660369687977`*^9, 3.4160660632613173`*^9}, {
   3.4160665450327063`*^9, 3.416066549389464*^9}, {3.4160677098531303`*^9, 
   3.4160677445789557`*^9}, {3.416069154678166*^9, 3.41606919681465*^9}, {
   3.416078881868895*^9, 3.416078892166409*^9}, {3.4161528982053757`*^9, 
   3.416152908717018*^9}, {3.416417105344108*^9, 3.4164171434350433`*^9}, {
   3.416417587198689*^9, 3.4164175958703003`*^9}, {3.416490823774013*^9, 
   3.416490830356449*^9}, {3.416492102827924*^9, 3.4164921241224613`*^9}, {
   3.416511878047935*^9, 3.416511891313239*^9}, {3.416585176472085*^9, 
   3.416585177237698*^9}, {3.416585211150734*^9, 3.416585223833824*^9}, {
   3.416585877603908*^9, 3.416585895058653*^9}, {3.416586078237522*^9, 
   3.416586091090446*^9}, {3.4173627386239*^9, 3.417362768898007*^9}, {
   3.417363453393559*^9, 3.4173634706420918`*^9}, {3.4174497549589653`*^9, 
   3.417449760339945*^9}, {3.4174499522131557`*^9, 3.417449954619363*^9}, {
   3.4175342810409403`*^9, 3.417534283063333*^9}, {3.4175343356702347`*^9, 
   3.4175343805358953`*^9}, {3.417534485117342*^9, 3.417534489483529*^9}, {
   3.417540061853334*^9, 3.417540068481328*^9}, {3.417540457707736*^9, 
   3.417540466442038*^9}, {3.417553040640254*^9, 3.417553105572578*^9}, {
   3.417553466499895*^9, 3.4175534697833967`*^9}, {3.417553519361898*^9, 
   3.417553522431278*^9}, {3.417619685170353*^9, 3.4176196893190813`*^9}, {
   3.417632546146656*^9, 3.417632553445294*^9}, {3.417812234967875*^9, 
   3.4178122455658617`*^9}, {3.4178802777281437`*^9, 3.41788028695955*^9}, {
   3.417882997975191*^9, 3.417883017980605*^9}, {3.419349971189107*^9, 
   3.419350012837522*^9}, {3.419350237534595*^9, 3.41935025682962*^9}, {
   3.419350404977736*^9, 3.419350422802478*^9}, {3.4193511945953207`*^9, 
   3.419351197097208*^9}, {3.41935208622565*^9, 3.419352092753688*^9}, {
   3.4193523676062202`*^9, 3.419352370549856*^9}, {3.419609852531019*^9, 
   3.419609980771303*^9}, {3.419686729555709*^9, 3.419686745934733*^9}, 
   3.419687251346305*^9, {3.419687298673715*^9, 3.419687299695389*^9}, {
   3.419692764057358*^9, 3.419692787870535*^9}, {3.419700563831668*^9, 
   3.419700581905826*^9}, {3.419701179780466*^9, 3.419701265401586*^9}, {
   3.419701330640868*^9, 3.419701354271978*^9}, {3.419705152242743*^9, 
   3.4197051579940443`*^9}, {3.4197084906589527`*^9, 3.419708491101619*^9}, {
   3.419709284451663*^9, 3.419709305344305*^9}, {3.419710522286982*^9, 
   3.419710550690591*^9}, {3.41971155032327*^9, 3.4197115543518677`*^9}, {
   3.4197116824102087`*^9, 3.419711685368293*^9}, {3.419712799267149*^9, 
   3.41971280369223*^9}, {3.419771499246072*^9, 3.4197717032493057`*^9}, {
   3.4197746186899433`*^9, 3.419774638265182*^9}, {3.419774799064412*^9, 
   3.419774839219026*^9}, {3.4197797374840393`*^9, 3.419779750114058*^9}, {
   3.419779787476606*^9, 3.4197798107844563`*^9}, {3.419780676082327*^9, 
   3.4197806991736917`*^9}, {3.419787187638015*^9, 3.419787206816132*^9}, {
   3.4197872915656643`*^9, 3.419787296513835*^9}, {3.419787643685731*^9, 
   3.419787748823997*^9}, {3.419788174424137*^9, 3.419788186101215*^9}, {
   3.419789798450103*^9, 3.4197898223487597`*^9}, {3.419897035726419*^9, 
   3.4198970406091833`*^9}, {3.4198970873606043`*^9, 3.419897227375922*^9}, {
   3.4198973773775787`*^9, 3.419897419034318*^9}, {3.419899747976269*^9, 
   3.419899760513585*^9}, {3.4199000590838537`*^9, 3.419900060682888*^9}, {
   3.419900235819496*^9, 3.4199002726663427`*^9}, {3.420025470849352*^9, 
   3.420025662227571*^9}, {3.420027432342826*^9, 3.420027448297244*^9}, {
   3.4200329665093327`*^9, 3.420032970711815*^9}, {3.4200587606284037`*^9, 
   3.420058769739212*^9}, {3.420059690886168*^9, 3.4200596994252663`*^9}, {
   3.4201129071494837`*^9, 3.420112921778212*^9}, {3.420137093522084*^9, 
   3.420137113224327*^9}, {3.420137868020496*^9, 3.420138102920063*^9}, {
   3.42013827546325*^9, 3.4201384052014837`*^9}, 3.420147708402411*^9, {
   3.421029950318142*^9, 3.421029950439419*^9}, {3.421029984787558*^9, 
   3.4210300283215723`*^9}, {3.4210783012503557`*^9, 
   3.4210783183255043`*^9}, {3.421108369618637*^9, 3.421108402447757*^9}, {
   3.421108452898576*^9, 3.421108453088004*^9}, {3.421108489753852*^9, 
   3.421108509345269*^9}, {3.421112643953224*^9, 3.4211126442623777`*^9}, {
   3.4211135314730663`*^9, 3.421113531628871*^9}, {3.421115451180428*^9, 
   3.4211154532222643`*^9}, {3.421116000762731*^9, 3.421116000922686*^9}, {
   3.4211162188165703`*^9, 3.421116218933848*^9}, {3.4211164738345127`*^9, 
   3.421116502106883*^9}, {3.4218444337043447`*^9, 3.421844440239311*^9}, {
   3.421844833309046*^9, 3.4218448402834578`*^9}, {3.4218456803628273`*^9, 
   3.421845699730682*^9}, {3.421845781582923*^9, 3.421845782218968*^9}, {
   3.421846004315662*^9, 3.42184601767624*^9}, {3.421846124882989*^9, 
   3.4218461267953978`*^9}, {3.421846253368093*^9, 3.421846257639203*^9}, {
   3.421846350633862*^9, 3.421846353712178*^9}, {3.421846424822638*^9, 
   3.421846464506632*^9}, {3.4218467146126547`*^9, 3.421846725609439*^9}, 
   3.421860895463505*^9, {3.421860938266222*^9, 3.4218609409042177`*^9}, {
   3.421862159527059*^9, 3.4218621660736847`*^9}, {3.421863571710874*^9, 
   3.4218635751486883`*^9}, 3.421864401116563*^9, {3.421864509347477*^9, 
   3.421864523183975*^9}, {3.422058122268139*^9, 3.42205813904154*^9}, {
   3.422058543175761*^9, 3.4220585524875307`*^9}, {3.438127868105344*^9, 
   3.4381278844374104`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"PayWage", "[", 
   RowBox[{
   "economy_List", ",", " ", "employerIndex_Integer", ",", " ", 
    "employeeIndex_Integer", ",", " ", "wagePayment_Real"}], "]"}], " ", ":=",
   "\[IndentingNewLine]", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"nextEconomy", "=", "economy"}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{"economyAgents", ",", "employerIndex", ",", "agentMoney"}], 
       "\[RightDoubleBracket]"}], "-=", "wagePayment"}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{"economyAgents", ",", "employeeIndex", ",", "agentMoney"}], 
       "\[RightDoubleBracket]"}], "+=", "wagePayment"}], ";", 
     "\[IndentingNewLine]", "nextEconomy"}]}], "\n", "   ", "]"}]}]], "Input",\

 CellChangeTimes->{{3.411157779020628*^9, 3.411157876726694*^9}, {
  3.415799091817729*^9, 3.415799091976349*^9}, {3.438127914785108*^9, 
  3.4381279153047543`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"EffectiveDemandRule", "[", 
   RowBox[{"economy_List", ",", " ", "agentIndex_Integer"}], "]"}], " ", ":=",
   "\n", "   ", 
  RowBox[{"Module", "[", " ", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", " ", "=", " ", "economy"}], ",", 
      RowBox[{"agent", " ", "=", " ", 
       RowBox[{
        RowBox[{
        "economy", "\[LeftDoubleBracket]", "economyAgents", 
         "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "agentIndex", 
        "\[RightDoubleBracket]"}]}], ",", "expenditure"}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"expenditure", " ", "=", " ", 
      RowBox[{
       RowBox[{"RandomReal", "[", "]"}], "*", 
       RowBox[{
       "agent", "\[LeftDoubleBracket]", "agentMoney", 
        "\[RightDoubleBracket]"}]}]}], ";", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
       RowBox[{
       "economyAgents", ",", " ", "agentIndex", ",", " ", "agentMoney"}], 
       "\[RightDoubleBracket]"}], " ", "-=", " ", "expenditure"}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{
      "nextEconomy", "\[LeftDoubleBracket]", "economyEffectiveDemand", 
       "\[RightDoubleBracket]"}], " ", "+=", " ", "expenditure"}], ";", 
     "\[IndentingNewLine]", "nextEconomy"}]}], "\n", "   ", "]"}]}]], "Input",\

 CellChangeTimes->{{3.411157608850163*^9, 3.411157643173172*^9}, {
   3.411838822592783*^9, 3.4118389118174763`*^9}, {3.411839140951926*^9, 
   3.411839151198718*^9}, {3.411839348871086*^9, 3.411839390273774*^9}, 
   3.412529344351091*^9, {3.414037729931018*^9, 3.414037750171301*^9}, {
   3.414038571383288*^9, 3.414038577459814*^9}, {3.414038641494501*^9, 
   3.4140386550298777`*^9}, {3.415798789868815*^9, 3.415798803633782*^9}, {
   3.4158191824858007`*^9, 3.415819220368794*^9}, {3.415905409911924*^9, 
   3.4159054118360367`*^9}, {3.415905918917199*^9, 3.4159059216350307`*^9}, {
   3.421975778295123*^9, 3.4219757795021667`*^9}, {3.421976262875757*^9, 
   3.421976263090262*^9}, {3.421976760824792*^9, 3.4219767752695093`*^9}, {
   3.422030837063416*^9, 3.4220308376082706`*^9}, {3.422030932629737*^9, 
   3.422030947793631*^9}, {3.422032704316216*^9, 3.4220327087179613`*^9}, {
   3.422033015672391*^9, 3.42203302403104*^9}, {3.422061659753772*^9, 
   3.42206166120852*^9}, {3.422062776197226*^9, 3.4220627766559277`*^9}, {
   3.4221512952707357`*^9, 3.422151297396678*^9}, {3.422152235170431*^9, 
   3.422152235607041*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"FirmIncomeRule", "[", 
    RowBox[{"economy_List", ",", " ", "agentIndex_Integer"}], "]"}], " ", ":=",
    "\[IndentingNewLine]", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       RowBox[{"nextEconomy", "=", "economy"}], ",", " ", 
       RowBox[{"agent", "=", 
        RowBox[{
         RowBox[{
         "economy", "\[LeftDoubleBracket]", "economyAgents", 
          "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "agentIndex", 
         "\[RightDoubleBracket]"}]}], ",", " ", "income", ",", 
       "recipientAgentIndex"}], "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"If", "[", 
       RowBox[{
        RowBox[{
         RowBox[{"IsEmployee", "[", "agent", "]"}], "||", 
         RowBox[{"IsEmployer", "[", "agent", "]"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"income", "=", 
          RowBox[{
           RowBox[{"RandomReal", "[", "]"}], "*", 
           RowBox[{
           "nextEconomy", "\[LeftDoubleBracket]", "economyEffectiveDemand", 
            "\[RightDoubleBracket]"}]}]}], ";", "\[IndentingNewLine]", 
         RowBox[{
          RowBox[{
          "nextEconomy", "\[LeftDoubleBracket]", "economyEffectiveDemand", 
           "\[RightDoubleBracket]"}], "-=", "income"}], ";", 
         "\[IndentingNewLine]", 
         RowBox[{"If", "[", 
          RowBox[{
           RowBox[{"IsEmployee", "[", "agent", "]"}], ",", 
           "\[IndentingNewLine]", 
           RowBox[{
            RowBox[{"recipientAgentIndex", "=", 
             RowBox[{
             "agent", "\[LeftDoubleBracket]", "agentEmployerIndex", 
              "\[RightDoubleBracket]"}]}], ";"}], ",", "\[IndentingNewLine]", 
           
           RowBox[{
            RowBox[{"recipientAgentIndex", "=", "agentIndex"}], ";"}]}], 
          "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
         RowBox[{
          RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
           RowBox[{
           "economyAgents", ",", " ", "recipientAgentIndex", ",", " ", 
            "agentMoney"}], "\[RightDoubleBracket]"}], " ", "+=", " ", 
          "income"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", 
      "\[IndentingNewLine]", "nextEconomy"}]}], "\n", "   ", "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{
  3.410934415015934*^9, {3.411110588967161*^9, 3.4111106890528793`*^9}, {
   3.411111522399561*^9, 3.4111115326619864`*^9}, {3.41115765572258*^9, 
   3.411157768416621*^9}, 3.411157883473419*^9, {3.411160370212336*^9, 
   3.4111603799154463`*^9}, {3.4111619878502913`*^9, 3.411161990447754*^9}, {
   3.41521458659144*^9, 3.415214667372387*^9}, {3.415216154261499*^9, 
   3.415216158774827*^9}, {3.415216430494277*^9, 3.415216437749303*^9}, {
   3.4152252377946177`*^9, 3.415225255185429*^9}, {3.41522611118349*^9, 
   3.4152261206311293`*^9}, {3.415300099003787*^9, 3.415300106163444*^9}, {
   3.415300647509034*^9, 3.41530065836695*^9}, {3.415798813207802*^9, 
   3.4157988164425898`*^9}, {3.415903829612928*^9, 3.4159038316725187`*^9}, {
   3.415904983628306*^9, 3.415904986146962*^9}, {3.4174516695958242`*^9, 
   3.417451682737193*^9}, {3.419350820199636*^9, 3.419350825956699*^9}, {
   3.419351886239561*^9, 3.4193518904297657`*^9}, {3.4193525776622868`*^9, 
   3.4193525824467897`*^9}, {3.419686789835215*^9, 3.4196867913633747`*^9}, 
   3.419687279979603*^9, 3.419779878248313*^9, 3.438127947915956*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"WagePaymentAndFiringRule", "[", 
   RowBox[{"economy_List", ",", " ", "agentIndex_Integer"}], "]"}], " ", ":=",
   "\[IndentingNewLine]", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", "=", "economy"}], ",", 
      RowBox[{"agent", "=", " ", 
       RowBox[{
        RowBox[{
        "economy", "\[LeftDoubleBracket]", "economyAgents", 
         "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "agentIndex", 
        "\[RightDoubleBracket]"}]}], ",", " ", "employeeIndices", ",", " ", 
      "i", ",", "wagePayment"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"IsEmployer", "[", "agent", "]"}], ",", "\[IndentingNewLine]", 
       
       RowBox[{
        RowBox[{"employeeIndices", " ", "=", " ", 
         RowBox[{
         "agent", "\[LeftDoubleBracket]", "agentEmployeeIndices", 
          "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"For", "[", 
         RowBox[{
          RowBox[{"i", " ", "=", " ", "1"}], ",", " ", 
          RowBox[{"i", " ", "<=", " ", 
           RowBox[{"Length", "[", "employeeIndices", "]"}]}], ",", " ", 
          RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", 
          RowBox[{
           RowBox[{"wagePayment", "=", 
            RowBox[{
             RowBox[{
              RowBox[{
              "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
               "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
              RowBox[{
              "employeeIndices", "\[LeftDoubleBracket]", "i", 
               "\[RightDoubleBracket]"}], "\[RightDoubleBracket]"}], 
             "\[LeftDoubleBracket]", "agentWageDemand", 
             "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", 
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{"wagePayment", "<=", 
              RowBox[{
               RowBox[{
                RowBox[{
                "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
                 "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
                "agentIndex", "\[RightDoubleBracket]"}], 
               "\[LeftDoubleBracket]", "agentMoney", 
               "\[RightDoubleBracket]"}]}], ",", "\[IndentingNewLine]", 
             RowBox[{
              RowBox[{"nextEconomy", "=", 
               RowBox[{"PayWage", "[", 
                RowBox[{"nextEconomy", ",", "agentIndex", ",", 
                 RowBox[{
                 "employeeIndices", "\[LeftDoubleBracket]", "i", 
                  "\[RightDoubleBracket]"}], ",", " ", "wagePayment"}], 
                "]"}]}], ";", "\[IndentingNewLine]", 
              RowBox[{
               RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
                RowBox[{
                "economyAgents", ",", "agentIndex", ",", "agentWage"}], 
                "\[RightDoubleBracket]"}], "=", "wagePayment"}], ";"}], ",", 
             "\[IndentingNewLine]", 
             RowBox[{
              RowBox[{"nextEconomy", "=", 
               RowBox[{"LeaveFirm", "[", 
                RowBox[{"nextEconomy", ",", " ", 
                 RowBox[{
                 "employeeIndices", "\[LeftDoubleBracket]", "i", 
                  "\[RightDoubleBracket]"}], ",", "agentIndex"}], "]"}]}], 
              ";", "\[IndentingNewLine]", 
              RowBox[{
               RowBox[{"nextEconomy", "\[LeftDoubleBracket]", 
                RowBox[{"economyAgents", ",", 
                 RowBox[{
                 "employeeIndices", "\[LeftDoubleBracket]", "i", 
                  "\[RightDoubleBracket]"}], ",", "agentWageDemand"}], 
                "\[RightDoubleBracket]"}], "=", 
               RowBox[{
                RowBox[{
                 RowBox[{
                 "nextEconomy", "\[LeftDoubleBracket]", "economyAgents", 
                  "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", 
                 RowBox[{
                 "employeeIndices", "\[LeftDoubleBracket]", "i", 
                  "\[RightDoubleBracket]"}], "\[RightDoubleBracket]"}], 
                "\[LeftDoubleBracket]", "agentWage", 
                "\[RightDoubleBracket]"}]}], ";"}]}], "\[IndentingNewLine]", 
            "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], 
      "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
     "nextEconomy"}]}], "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.411108450508264*^9, 3.411108460815968*^9}, {
   3.411110439767927*^9, 3.411110567359788*^9}, {3.4111115657250338`*^9, 
   3.411111626526507*^9}, {3.411153786071848*^9, 3.411153786609172*^9}, {
   3.4111554545669727`*^9, 3.411155477953867*^9}, {3.41115711408171*^9, 
   3.411157119969677*^9}, {3.4111578932954206`*^9, 3.411157900599257*^9}, {
   3.4111579310739927`*^9, 3.411158066598878*^9}, {3.411158721081273*^9, 
   3.411158736355476*^9}, {3.4111599528394527`*^9, 3.41115995320778*^9}, {
   3.411414841325172*^9, 3.411414854291091*^9}, {3.4114185255307693`*^9, 
   3.411418771822073*^9}, {3.411418825645262*^9, 3.411418950047867*^9}, {
   3.411419003740999*^9, 3.41141900922491*^9}, {3.4114190924433393`*^9, 
   3.41141909561579*^9}, {3.4114191391204033`*^9, 3.411419140954314*^9}, {
   3.411419953007955*^9, 3.411419985523321*^9}, {3.412527118188361*^9, 
   3.412527243532153*^9}, {3.412528474002902*^9, 3.4125284791704817`*^9}, {
   3.4125285688785954`*^9, 3.412528587938959*^9}, {3.412619439161809*^9, 
   3.412619442095029*^9}, 3.412620210824286*^9, {3.4126302961316013`*^9, 
   3.412630296135384*^9}, {3.412630343600771*^9, 3.412630344176359*^9}, {
   3.412630399229026*^9, 3.4126305125190697`*^9}, 3.4126307569831457`*^9, {
   3.412630875793674*^9, 3.412630878885358*^9}, {3.412631951336855*^9, 
   3.4126319686951857`*^9}, {3.412698261437542*^9, 3.412698261440792*^9}, {
   3.414252544871722*^9, 3.414252565861452*^9}, {3.414966053908197*^9, 
   3.4149660688881273`*^9}, {3.414966358933907*^9, 3.414966373437476*^9}, {
   3.415284501131819*^9, 3.415284508073318*^9}, {3.415285678642284*^9, 
   3.415285683255287*^9}, {3.4156351363887463`*^9, 3.415635149785507*^9}, {
   3.415635184175178*^9, 3.4156352707914352`*^9}, {3.4156353226956377`*^9, 
   3.415635353276061*^9}, {3.415635882999446*^9, 3.415635886725071*^9}, {
   3.415798832026328*^9, 3.415798840627141*^9}, {3.415798999236453*^9, 
   3.4157990133203707`*^9}, {3.4157991006568823`*^9, 3.41579910813218*^9}, {
   3.4158001292575703`*^9, 3.4158001604881763`*^9}, {3.415819271118346*^9, 
   3.4158192825595903`*^9}, {3.4158193253442097`*^9, 3.4158193284794807`*^9}, 
   3.4158838110051823`*^9, {3.415907647738278*^9, 3.415907650312161*^9}, {
   3.415908234309115*^9, 3.415908288287624*^9}, {3.41606618654029*^9, 
   3.41606623020109*^9}, {3.416417902439872*^9, 3.416417950985758*^9}, {
   3.416418093882662*^9, 3.4164180998714857`*^9}, {3.416418137713152*^9, 
   3.41641814043361*^9}, {3.416491043944852*^9, 3.416491050741824*^9}, {
   3.416491185799508*^9, 3.4164911993864183`*^9}, {3.41649134009025*^9, 
   3.416491354622821*^9}, {3.41649397186909*^9, 3.4164939768856707`*^9}, {
   3.416494398086055*^9, 3.416494402893628*^9}, {3.416501816919466*^9, 
   3.416501822555335*^9}, {3.416511921223858*^9, 3.416511927883572*^9}, {
   3.416585074124959*^9, 3.416585097220632*^9}, {3.41658643132131*^9, 
   3.416586447127651*^9}, {3.417451664761648*^9, 3.4174516648973083`*^9}, {
   3.418574947729885*^9, 3.41857505339368*^9}, {3.418575248444372*^9, 
   3.418575251951305*^9}, {3.419686796040506*^9, 3.4196868009527607`*^9}, {
   3.419687435092588*^9, 3.419687438644083*^9}, 3.419690469613537*^9, {
   3.419779893744863*^9, 3.419779926680296*^9}, {3.419786744650197*^9, 
   3.419786783111703*^9}, {3.420024492511471*^9, 3.420024524373661*^9}, {
   3.420043333846599*^9, 3.420043349801272*^9}, {3.420137093579452*^9, 
   3.420137153397089*^9}, {3.4201382754971952`*^9, 3.4201382892489243`*^9}, {
   3.420138450470183*^9, 3.420138520650584*^9}, 3.420830342694522*^9, 
   3.4208306814732447`*^9, 3.4208309163165903`*^9, {3.421862190422615*^9, 
   3.421862213837923*^9}, {3.421862805158722*^9, 3.421862816201117*^9}, {
   3.438127954443713*^9, 3.4381279957143784`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"ProcessAgentRule", "[", 
   RowBox[{"economy_List", ",", " ", "agentIndex_Integer"}], "]"}], " ", ":=",
   "\[IndentingNewLine]", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", "=", "economy"}], ",", 
      RowBox[{"rules", "=", 
       RowBox[{"{", 
        RowBox[{
        "HiringRule", ",", "EffectiveDemandRule", ",", "FirmIncomeRule", ",", 
         "WagePaymentAndFiringRule"}], "}"}]}], ",", "i"}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"For", "[", 
      RowBox[{
       RowBox[{"i", "=", "1"}], ",", 
       RowBox[{"i", "\[LessEqual]", 
        RowBox[{"Length", "[", "rules", "]"}]}], ",", 
       RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"nextEconomy", "=", 
         RowBox[{
          RowBox[{
          "rules", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "@@",
           
          RowBox[{"{", 
           RowBox[{"nextEconomy", ",", "agentIndex"}], "}"}]}]}], ";"}]}], 
      "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
     "nextEconomy"}]}], "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.4111099774259377`*^9, 3.411110017063261*^9}, {
   3.411110055273416*^9, 3.411110116894932*^9}, {3.411110168288312*^9, 
   3.4111102328285513`*^9}, {3.4111102647731667`*^9, 3.411110331409268*^9}, {
   3.411110368189831*^9, 3.4111104032864847`*^9}, {3.411111058114563*^9, 
   3.411111133131454*^9}, {3.411111499762504*^9, 3.41111150588701*^9}, {
   3.411111548987974*^9, 3.411111554500189*^9}, {3.411111643563958*^9, 
   3.411111646742878*^9}, {3.411111695547904*^9, 3.411111702154705*^9}, {
   3.411158205756709*^9, 3.411158206590653*^9}, {3.41252725387719*^9, 
   3.4125272562341843`*^9}, {3.412528599041546*^9, 3.412528600556733*^9}, {
   3.414037675105761*^9, 3.414037699778626*^9}, {3.414038594479698*^9, 
   3.414038597489624*^9}, {3.414164694957822*^9, 3.414164704665785*^9}, {
   3.414165413224283*^9, 3.414165437334516*^9}, {3.414165915868404*^9, 
   3.414165918742915*^9}, {3.4141665482761106`*^9, 3.414166562121955*^9}, {
   3.414168163523452*^9, 3.41416819462008*^9}, {3.414170414759346*^9, 
   3.414170460790532*^9}, {3.414170877088027*^9, 3.4141709000687447`*^9}, {
   3.414171635458742*^9, 3.414171645676628*^9}, {3.414175003305153*^9, 
   3.414175008353375*^9}, {3.414184953511853*^9, 3.414184991460108*^9}, {
   3.414185348011101*^9, 3.4141853767081633`*^9}, {3.4141854979666367`*^9, 
   3.4141855022559433`*^9}, {3.41418576036486*^9, 3.4141857716461983`*^9}, {
   3.414186638666272*^9, 3.414186649565587*^9}, {3.4142535782270193`*^9, 
   3.414253585686811*^9}, {3.414254084556795*^9, 3.414254106841914*^9}, {
   3.414254557042132*^9, 3.414254564474091*^9}, {3.414254962107362*^9, 
   3.414254978436884*^9}, {3.41425543769858*^9, 3.414255445086658*^9}, {
   3.4152227302269783`*^9, 3.415222738947397*^9}, {3.4152230679645777`*^9, 
   3.415223075408811*^9}, {3.415279111730494*^9, 3.41527911648597*^9}, {
   3.4152805953151693`*^9, 3.415280607616701*^9}, {3.415283390822071*^9, 
   3.4152833937705584`*^9}, {3.4152868696645393`*^9, 3.415286871868266*^9}, {
   3.415287635890592*^9, 3.415287639084309*^9}, {3.415297422293692*^9, 
   3.4152974507493553`*^9}, {3.415297744810191*^9, 3.415297789331511*^9}, {
   3.415299012001151*^9, 3.415299014822035*^9}, {3.4153743267032347`*^9, 
   3.415374360418489*^9}, {3.415374423336658*^9, 3.4153744235078697`*^9}, {
   3.415374961837453*^9, 3.415375018309898*^9}, {3.415377402652603*^9, 
   3.415377424445717*^9}, {3.41538218513901*^9, 3.415382186882107*^9}, {
   3.415382264207644*^9, 3.4153823001179647`*^9}, {3.415460450327725*^9, 
   3.415460479235786*^9}, {3.415463313480311*^9, 3.415463344256374*^9}, {
   3.415547181782061*^9, 3.4155472034401703`*^9}, {3.4155486913764467`*^9, 
   3.415548706550206*^9}, {3.4155497121282053`*^9, 3.415549722527732*^9}, {
   3.415566755995064*^9, 3.4155667683109837`*^9}, {3.415566937319985*^9, 
   3.415566944662714*^9}, {3.415567533539434*^9, 3.4155675484350653`*^9}, {
   3.415567636673978*^9, 3.415567647534663*^9}, {3.415568168200026*^9, 
   3.415568206807191*^9}, {3.415568902255081*^9, 3.4155689030354652`*^9}, {
   3.415634264506868*^9, 3.415634332749213*^9}, {3.415635072813148*^9, 
   3.415635078620219*^9}, {3.4156359563035917`*^9, 3.415635960416492*^9}, {
   3.4156365373825607`*^9, 3.415636617722394*^9}, {3.4156370979684057`*^9, 
   3.415637114094554*^9}, {3.415798866437957*^9, 3.415798870802706*^9}, {
   3.4158193673937902`*^9, 3.415819371249482*^9}, 3.415819633548609*^9, {
   3.415820095548031*^9, 3.415820105197551*^9}, {3.415820184631369*^9, 
   3.415820192881454*^9}, {3.415820407851617*^9, 3.415820413255015*^9}, {
   3.415884108349063*^9, 3.4158841389502363`*^9}, {3.415884852857308*^9, 
   3.415884882958888*^9}, {3.415885372456492*^9, 3.415885387968568*^9}, {
   3.415886029567877*^9, 3.41588604155686*^9}, {3.415886272921371*^9, 
   3.415886280777853*^9}, {3.415886477377643*^9, 3.415886498063958*^9}, {
   3.415886662207355*^9, 3.415886669582631*^9}, {3.415886944795217*^9, 
   3.415886953957588*^9}, {3.415888265283368*^9, 3.415888273540463*^9}, {
   3.4158885277853823`*^9, 3.4158885370728292`*^9}, {3.415902846535375*^9, 
   3.415902846677608*^9}, {3.415903580530472*^9, 3.4159035807015676`*^9}, {
   3.415905426285449*^9, 3.4159054336869183`*^9}, {3.4159058950309677`*^9, 
   3.4159059036158657`*^9}, 3.4159095301327057`*^9, 3.4159102752615337`*^9, {
   3.415910321958231*^9, 3.4159103299562407`*^9}, {3.415911023003601*^9, 
   3.41591103020492*^9}, 3.415980176544895*^9, {3.415982138941298*^9, 
   3.415982147728279*^9}, {3.415982447610806*^9, 3.415982457584338*^9}, {
   3.4159826728977127`*^9, 3.415982682066558*^9}, {3.415982984975272*^9, 
   3.415982991786296*^9}, {3.4160663892334957`*^9, 3.416066415416003*^9}, {
   3.416069053142441*^9, 3.416069055462001*^9}, {3.4160696142987413`*^9, 
   3.416069673055677*^9}, {3.416069937035413*^9, 3.416069964239403*^9}, {
   3.4160700848725863`*^9, 3.416070094210477*^9}, {3.416154908593451*^9, 
   3.416154912453513*^9}, {3.4161549536926117`*^9, 3.416154966161508*^9}, {
   3.416171513238699*^9, 3.41617151652029*^9}, {3.416417203703021*^9, 
   3.4164172054818563`*^9}, {3.416492635979409*^9, 3.4164926373187838`*^9}, {
   3.416493750734232*^9, 3.4164937524797277`*^9}, {3.416501472757682*^9, 
   3.416501499106269*^9}, {3.41650180008503*^9, 3.4165018120071707`*^9}, 
   3.4165119525031767`*^9, {3.418485226348606*^9, 3.4184852679505587`*^9}, {
   3.4184858598784657`*^9, 3.4184858664972343`*^9}, {3.418485904388115*^9, 
   3.418485943393096*^9}, {3.418486560572407*^9, 3.418486573214925*^9}, {
   3.418571024285584*^9, 3.418571078796937*^9}, {3.4185731135842733`*^9, 
   3.41857312070391*^9}, {3.4185752827951603`*^9, 3.4185753185397253`*^9}, {
   3.418575544877125*^9, 3.418575562615144*^9}, {3.4185767453668003`*^9, 
   3.4185767758034887`*^9}, {3.418587406584627*^9, 3.418587412964675*^9}, {
   3.418657741906505*^9, 3.418657765565917*^9}, {3.418657971018468*^9, 
   3.4186579806975946`*^9}, {3.419686805018091*^9, 3.419686805446394*^9}, 
   3.419776516366132*^9, 3.419777188504531*^9, 3.420148545463146*^9, 
   3.4202169144704437`*^9, {3.422030846229738*^9, 3.42203088077666*^9}, {
   3.422030960145434*^9, 3.4220309624592752`*^9}, {3.4220599412207613`*^9, 
   3.422059969556264*^9}, {3.4220604036098347`*^9, 3.422060411071384*^9}, {
   3.4220607956364603`*^9, 3.4220608063714123`*^9}, 3.438128016598637*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"OneMonthRule", "[", "economy_List", "]"}], " ", ":=", 
  "\[IndentingNewLine]", 
  RowBox[{"Module", "[", " ", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomy", "=", "economy"}], ",", 
      RowBox[{"numAgents", "=", 
       RowBox[{"Length", "[", 
        RowBox[{
        "economy", "\[LeftDoubleBracket]", "economyAgents", 
         "\[RightDoubleBracket]"}], "]"}]}], ",", "agentProcessList"}], "}"}],
     ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"agentProcessList", "=", 
      RowBox[{"RandomChoice", "[", 
       RowBox[{
        RowBox[{"Range", "[", "numAgents", "]"}], ",", "numAgents"}], "]"}]}],
      ";", "\[IndentingNewLine]", 
     RowBox[{"Fold", "[", 
      RowBox[{
      "ProcessAgentRule", ",", "nextEconomy", ",", "agentProcessList"}], 
      "]"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.41093590940476*^9, 3.41093596938242*^9}, {
  3.4111109335757637`*^9, 3.4111110323455143`*^9}, {3.411150213820797*^9, 
  3.411150246563014*^9}, {3.411152420906769*^9, 3.411152426795055*^9}, {
  3.411158214081749*^9, 3.4111583829519*^9}, {3.4118012963337803`*^9, 
  3.411801394615885*^9}, {3.411801454559256*^9, 3.4118014743684263`*^9}, {
  3.4118015072939053`*^9, 3.411801507951495*^9}, {3.411806489931726*^9, 
  3.411806490687978*^9}, {3.41180661738335*^9, 3.411806617511002*^9}, {
  3.413907995758872*^9, 3.413908036878442*^9}, {3.4139085004054728`*^9, 
  3.413908506200694*^9}, {3.4140359217396107`*^9, 3.41403592869739*^9}, {
  3.414036411206613*^9, 3.4140364226855097`*^9}, {3.414037282896154*^9, 
  3.414037292507172*^9}, {3.414038663734189*^9, 3.41403866987645*^9}, {
  3.414039991159274*^9, 3.414039997098073*^9}, {3.41404099579862*^9, 
  3.414041002076249*^9}, {3.414041420216851*^9, 3.4140414595334473`*^9}, {
  3.414185892641821*^9, 3.414185898382824*^9}, {3.414254115773231*^9, 
  3.414254124319862*^9}, {3.414255824784479*^9, 3.414255840915312*^9}, {
  3.414256300818884*^9, 3.414256307109137*^9}, {3.414966412002151*^9, 
  3.414966420099958*^9}, {3.414966497397274*^9, 3.414966501364729*^9}, {
  3.414966553880891*^9, 3.414966564594817*^9}, {3.41521471327184*^9, 
  3.415214727622449*^9}, {3.415223087010819*^9, 3.415223096570858*^9}, {
  3.415224080573227*^9, 3.415224086282338*^9}, {3.415278947635207*^9, 
  3.415278954971665*^9}, {3.4152790367319927`*^9, 3.415279043975663*^9}, {
  3.415279857030676*^9, 3.41527986390093*^9}, {3.4152805483470993`*^9, 
  3.415280556368305*^9}, {3.415281688993711*^9, 3.415281695858397*^9}, {
  3.415282628098002*^9, 3.415282635594212*^9}, {3.415283310458558*^9, 
  3.4152833175923643`*^9}, {3.415300687392561*^9, 3.415300694293116*^9}, {
  3.415301200430436*^9, 3.415301207685541*^9}, {3.415301528948606*^9, 
  3.415301534625842*^9}, {3.4157988863161793`*^9, 3.4157988895723667`*^9}, {
  3.415799183595055*^9, 3.415799183740189*^9}, {3.415800092271275*^9, 
  3.4158001050819817`*^9}, {3.415887756618073*^9, 3.415887758746455*^9}, {
  3.415887986739173*^9, 3.415887989113646*^9}, {3.416071262843896*^9, 
  3.4160712722113857`*^9}, {3.4161532628751097`*^9, 3.4161532674347677`*^9}, {
  3.416417211951252*^9, 3.416417216561598*^9}, {3.41641953827048*^9, 
  3.416419542816901*^9}, {3.416420257200056*^9, 3.416420262412671*^9}, {
  3.416492384530336*^9, 3.416492389129499*^9}, {3.416494776408394*^9, 
  3.416494781410262*^9}, {3.416502161039173*^9, 3.416502165640826*^9}, {
  3.416504253962566*^9, 3.416504258536035*^9}, {3.41651196041856*^9, 
  3.4165119605801563`*^9}, {3.4173637685289392`*^9, 3.4173637777394876`*^9}, {
  3.417364353641168*^9, 3.417364356655738*^9}, {3.4173647498610477`*^9, 
  3.4173647997306957`*^9}, {3.4173648675185347`*^9, 3.4173649562439337`*^9}, {
  3.417365274187148*^9, 3.4173653066836042`*^9}, {3.417451133520164*^9, 
  3.417451144850099*^9}, {3.4174519190082893`*^9, 3.4174519337542257`*^9}, {
  3.418572231738118*^9, 3.4185722360532312`*^9}, {3.418573091311002*^9, 
  3.4185730989670258`*^9}, {3.419687041203388*^9, 3.41968704543051*^9}, {
  3.4196875896229897`*^9, 3.4196875936638727`*^9}, {3.419690622170371*^9, 
  3.419690622398675*^9}, {3.419775493481639*^9, 3.4197755032710752`*^9}, {
  3.4197760439530153`*^9, 3.41977604655929*^9}, {3.419776646722601*^9, 
  3.419776654475012*^9}, {3.4197770214900913`*^9, 3.419777025654316*^9}, {
  3.4197770976232*^9, 3.419777118183199*^9}, {3.4197772820955353`*^9, 
  3.419777287037263*^9}, {3.4197815636664267`*^9, 3.419781569168214*^9}, {
  3.4197816380431843`*^9, 3.4197816427752657`*^9}, {3.419957692381124*^9, 
  3.4199577014074497`*^9}, {3.419957842453042*^9, 3.419957845844102*^9}, {
  3.4200247175465517`*^9, 3.420024725206711*^9}, {3.420025888243222*^9, 
  3.420025893134451*^9}, {3.4200260044683933`*^9, 3.420026008633192*^9}, {
  3.4200266534311447`*^9, 3.420026657954015*^9}, {3.420138582495654*^9, 
  3.4201385826981993`*^9}, {3.421116617403697*^9, 3.421116775440667*^9}, {
  3.4211176066840677`*^9, 3.421117610535912*^9}, {3.421720869554595*^9, 
  3.421720885397731*^9}, {3.421844374799656*^9, 3.4218443768778477`*^9}, {
  3.421864604291519*^9, 3.421864605601069*^9}, {3.4220316759055843`*^9, 
  3.42203168945763*^9}, {3.422032523984996*^9, 3.422032527939715*^9}, {
  3.422032567133686*^9, 3.422032571619227*^9}, {3.4220333812575274`*^9, 
  3.4220333868408127`*^9}, {3.4381280846045723`*^9, 3.438128087344532*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"OneYearRule", "[", "economyTrajectory_List", "]"}], " ", ":=", 
  "\[IndentingNewLine]", 
  RowBox[{"Module", "[", " ", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"nextEconomyTrajectory", "=", "economyTrajectory"}], ",", 
      RowBox[{"year", "=", 
       RowBox[{"{", "}"}]}], ",", 
      RowBox[{"currentState", "=", 
       RowBox[{"Last", "[", "economyTrajectory", "]"}]}]}], "}"}], ",", "\n", 
    "     ", 
    RowBox[{
     RowBox[{"Do", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{
        RowBox[{"year", "=", 
         RowBox[{"Append", "[", 
          RowBox[{"year", ",", 
           RowBox[{"OneMonthRule", "[", "currentState", "]"}]}], "]"}]}], ";",
         "\[IndentingNewLine]", 
        RowBox[{"currentState", "=", 
         RowBox[{"Last", "[", "year", "]"}]}], ";"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"{", "12", "}"}]}], "\[IndentingNewLine]", "]"}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"nextEconomyTrajectory", "=", 
      RowBox[{"Join", "[", 
       RowBox[{"nextEconomyTrajectory", ",", "year"}], "]"}]}], ";", 
     "\[IndentingNewLine]", "nextEconomyTrajectory"}]}], "\n", "   ", 
   "]"}]}]], "Input",
 CellChangeTimes->{{3.411158389056416*^9, 3.411158449180966*^9}, {
   3.421262134981741*^9, 3.421262138882452*^9}, {3.421262209357006*^9, 
   3.421262328439055*^9}, 3.421262430696443*^9, {3.421262507993175*^9, 
   3.421262552320445*^9}, {3.421262601791088*^9, 3.421262604980043*^9}, {
   3.421262647729113*^9, 3.4212626479009237`*^9}, {3.421262678221512*^9, 
   3.42126267837471*^9}, {3.421262717541049*^9, 3.421262727629128*^9}, {
   3.421262893615569*^9, 3.42126304290121*^9}, {3.4212630936668386`*^9, 
   3.421263096510373*^9}, {3.421263350042453*^9, 3.421263362490219*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"EvaluateModel", "[", 
   RowBox[{"economyTrajectory_List", ",", " ", "numYears_Integer"}], "]"}], 
  " ", ":=", "\n", "   ", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"nextEconomyTrajectory", "=", "economyTrajectory"}], "}"}], ",", 
    "\n", "      ", 
    RowBox[{
     RowBox[{"Do", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{
        RowBox[{"nextEconomyTrajectory", " ", "=", " ", 
         RowBox[{"OneYearRule", "[", "nextEconomyTrajectory", "]"}]}], ";"}], 
       ",", "\[IndentingNewLine]", 
       RowBox[{"{", "numYears", "}"}]}], "\n", "      ", "]"}], ";", 
     "\[IndentingNewLine]", "nextEconomyTrajectory"}]}], 
   "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.438128384487379*^9, 3.4381284024803953`*^9}, {
  3.4382246879885*^9, 3.438224690461062*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"EvaluateModel", "[", 
   RowBox[{
   "numAgents_Integer", ",", " ", "initialMoneyEndowment_Real", ",", 
    "numYears_Integer"}], "]"}], " ", ":=", "\n", "   ", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"economy", "=", 
       RowBox[{"NewEconomy", "[", 
        RowBox[{"numAgents", ",", " ", "initialMoneyEndowment"}], "]"}]}], 
      ",", "economyTrajectory"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"economyTrajectory", " ", "=", " ", 
      RowBox[{"{", "economy", "}"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"economyTrajectory", " ", "=", " ", 
      RowBox[{"EvaluateModel", "[", 
       RowBox[{"economyTrajectory", ",", " ", "numYears"}], "]"}]}]}]}], 
   "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.411111782264927*^9, 3.411111785038556*^9}, {
  3.4111585160823593`*^9, 3.411158526499107*^9}, {3.411158556541884*^9, 
  3.4111585631721563`*^9}, {3.4197731826069*^9, 3.419773215354622*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", " ", "Run", " ", "*)"}], "\[IndentingNewLine]", 
  RowBox[{"(*", " ", 
   RowBox[{
   "Output", " ", "is", " ", "a", " ", "trajectory", " ", "of", " ", 
    "simulation", " ", "states"}], " ", "*)"}], "\[IndentingNewLine]", 
  RowBox[{"trajectory", "=", 
   RowBox[{"EvaluateModel", "[", 
    RowBox[{"50", " ", 
     RowBox[{"(*", " ", 
      RowBox[{"number", " ", "of", " ", "agents"}], " ", "*)"}], ",", "10.0", 
     " ", 
     RowBox[{"(*", " ", 
      RowBox[{"initial", " ", "money", " ", "endowment"}], " ", "*)"}], ",", 
     "10"}], " ", 
    RowBox[{"(*", " ", 
     RowBox[{
     "number", " ", "of", " ", "years", " ", "to", " ", "run", " ", 
      "simulation"}], " ", "*)"}], "]"}]}]}]], "Input",
 CellChangeTimes->{{3.438128115988455*^9, 3.4381281387827272`*^9}, 
   3.438128418876975*^9, {3.43822419926289*^9, 3.438224212194745*^9}, {
   3.4382244367851963`*^9, 3.438224498667926*^9}, {3.4382248490465937`*^9, 
   3.438224876771719*^9}}]
},
WindowSize->{1248, 970},
WindowMargins->{{201, Automatic}, {27, Automatic}},
FrontEndVersion->"6.0 for Linux x86 (64-bit) (June 19, 2007)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[569, 21, 2692, 61, 361, "Input"],
Cell[3264, 84, 361, 9, 61, "Input"],
Cell[3628, 95, 3116, 62, 286, "Input"],
Cell[6747, 159, 8987, 155, 411, "Input"],
Cell[15737, 316, 1577, 37, 186, "Input"],
Cell[17317, 355, 2203, 46, 186, "Input"],
Cell[19523, 403, 12307, 214, 561, "Input"],
Cell[31833, 619, 1079, 26, 161, "Input"],
Cell[32915, 647, 2512, 51, 186, "Input"],
Cell[35430, 700, 3451, 73, 336, "Input"],
Cell[38884, 775, 8184, 148, 411, "Input"],
Cell[47071, 925, 7497, 117, 186, "Input"],
Cell[54571, 1044, 5360, 85, 136, "Input"],
Cell[59934, 1131, 1805, 40, 261, "Input"],
Cell[61742, 1173, 868, 21, 211, "Input"],
Cell[62613, 1196, 1027, 23, 136, "Input"],
Cell[63643, 1221, 995, 23, 86, "Input"]
}
]
*)

(* End of internal cache information *)
